package com.toulouseculture;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.toulouseculture.bo.CinemaPlace;
import com.toulouseculture.controller.CulturePlaceController;

public class CinemaActivity extends Activity {

	// private static final int MENU_HELP = Menu.FIRST;
	//
	// private static final int DIALOG_HELP = 0;

	CinemaPlace currentCinema = null;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.cinema);

		// get the row
		Integer placeId = null;
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			placeId = new Long(extras.getLong(CulturePlaceController.CULTURE_PLACE_ID)).intValue();
		}

		CulturePlaceController controller = CulturePlaceController.getInstance();

		currentCinema = (CinemaPlace) controller.getCulturePlaceById(placeId);

		TextView title = (TextView) findViewById(R.id.cinemaTitle);
		title.setText(currentCinema.getName());

		Button urlButton = (Button) findViewById(R.id.cinemaUrlButton);
		urlButton.setText(currentCinema.getUrl());

		urlButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(currentCinema.getUrl()));
				startActivity(myIntent);
			}
		});

		Button callButton = (Button) findViewById(R.id.cinemaCallButton);
		callButton.setText(currentCinema.getPhone());
		callButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				try {
					Intent callIntent = new Intent(Intent.ACTION_CALL);
					callIntent.setData(Uri.parse("tel:" + currentCinema.getPhone()));
					startActivity(callIntent);
				} catch (ActivityNotFoundException e) {
					Log.e("helloandroid dialing example", "Call failed", e);
				}

			}
		});

		Button compassButton = (Button) findViewById(R.id.cinemaCompassButton);
		compassButton.setText(currentCinema.getNoStreet() + " " + currentCinema.getAddress());
		compassButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent i = new Intent(CinemaActivity.this, CulturePlaceMapsActivity.class);
				i.putExtra(CulturePlaceController.CULTURE_PLACE_ID, new Long(currentCinema.getId()));
				startActivity(i);
			}
		});

		Button showTimesButton = (Button) findViewById(R.id.cinemaShowtimesButton);
		showTimesButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent i = new Intent(CinemaActivity.this, CinemaProgramListActivity.class);
				i.putExtra(CulturePlaceController.CULTURE_PLACE_ID, new Long(currentCinema.getId()));
				startActivity(i);
			}
		});

	}
	// @Override
	// public boolean onCreateOptionsMenu(Menu menu) {
	// super.onCreateOptionsMenu(menu);
	// menu.add(0, MENU_HELP, 0, R.string.Help);
	// MenuItem item = menu.getItem(0);
	// item.setIcon(android.R.drawable.ic_menu_info_details);
	// return true;
	// }
	//
	// @Override
	// public boolean onMenuItemSelected(int featureId, MenuItem item) {
	// switch (item.getItemId()) {
	// case MENU_HELP:
	// showDialog(DIALOG_HELP);
	// }
	//
	// return super.onMenuItemSelected(featureId, item);
	// }
	//
	// @Override
	// protected Dialog onCreateDialog(int id) {
	// Dialog dialog;
	// switch (id) {
	// case DIALOG_HELP:
	// dialog = new Dialog(this);
	//
	// // dialog.setContentView(android.R.layout);
	// dialog.setTitle(R.string.Help);
	// TextView tv = new TextView(this);
	// tv.setPadding(5, 0, 0, 5);
	// tv.setText(R.string.HelpFavoriContent);
	// dialog.setContentView(tv);
	//
	// break;
	// default:
	// dialog = null;
	// }
	// return dialog;
	// }

}